<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>游戏列表</title>

    <script charset="utf-8" type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="/js/com.wxd.js"></script>
    <script charset="utf-8" type="text/javascript" src="/pageview.js"></script>

    <link rel="stylesheet" type="text/css" href="/style/com.wxd.css"/>
    <link rel="stylesheet" type="text/css" href="/style/table.css"/>

    <style>
        html, body {display: block;width: 100%;height: 100%;overflow: hidden;overflow-x: auto;background: rgb(255, 255, 255);}

        html, body, div, table, tr, td {margin: 0px;border: 0px;box-sizing: border-box;}

        a:link {color: #0866b4;}

        a:visited { color: #0866b4;}

        label {padding-left: 5px;padding-right: 5px;}

    </style>

    <script>

        function parentLoading() {
            wxd.loading();
        }

        function parentLoading_close() {
            wxd.loading_close();
        }

        function parentNotice(content, isError, closeTime) {
            wxd.message.notice(content, isError, closeTime);
        }

        function parentAlert(msg) {
            wxd.message.alert(
                msg,
                "提示：",
                "关闭",
                () => {
                    setTimeout(() => {
                        $("#div_load_box").parent().remove();
                        search();
                    }, 1);
                }
            );
        }

        function truncates(gameId, gameName) {
            wxd.message.alert(
                `确定对游戏 ${gameName}(gameId=${gameId}) 进行清档操作嘛？数据不可恢复~~~`,
                "警告：",
                "确定",
                () => {
                    let map = new wxd.Map().loadSearch();
                    wxd.netty.post("/game/truncates", map.toString(),
                        (data) => {
                            if (data.code === 1) {
                                parentNotice(`${gameName}(${gameId}) 清档成功`);
                            } else {
                                parentAlert(`${gameName}(${gameId}) 清档失败 -> ${data.msg}`);
                            }
                        }
                    );
                },
                "取消"
            );
        }


        function operate(gameId, type) {
            let map = new wxd.Map().loadSearch();
            map.put("gameId", gameId);
            map.put("type", type);
            wxd.netty.post("/game/refreshKey", map.toString(),
                (data) => {
                    if (data.code === 1) {
                        parentNotice(`更新完成`);
                        search();
                    } else {
                        parentAlert(`${gameName}(${gameId}) 清档失败 -> ${data.msg}`);
                    }
                }
            );
        }

        let pageView;

        function search() {
            wxd.loading();
            let urlQuery = new wxd.Map().loadSearch();
            urlQuery.put("search", $("#search").val());
            pageView.remoteGetData(urlQuery);
        }

        function createRow(index, row) {
            return `
    <tr>
            <td style="width: 240px;">
                <a href="javascript:void(0);" onclick="truncates(${row.uid}, '${row.name}');return false;" title="清档">清档</a>
                <a href="javascript:void(0);" onclick="operate(${row.uid}, 'app');return false;" title="更新 AppKey">appToken</a>
                <a href="javascript:void(0);" onclick="operate(${row.uid}, 'recharge');return false;" title="更新 RechargeKey">rechargeToken</a>
                <a href="javascript:void(0);" onclick="operate(${row.uid}, 'log');return false;" title="更新 AppKey">logToken</a>
            </td>
            <td tips="true" style="width: 58px;">${index}</td>
            <td tips="true" style="width: 58px;">${row.uid}</td>
            <td tips="true" style="width: 120px;">${row.name}</td>
            <td tips="true" style="width: 120px;">${row.icon}</td>
            <td tips="true" style="width: 120px;">${row.createTime}</td>
            <td tips="true" style="width: 140px;" ondblclick="wxd.copy('${row.appToken}');wxd.message.notice('复制成功')">${row.appToken}</td>
            <td tips="true" style="width: 140px;" ondblclick="wxd.copy('${row.rechargeToken}');wxd.message.notice('复制成功')">${row.rechargeToken}</td>
            <td tips="true" style="width: 140px;" ondblclick="wxd.copy('${row.logToken}');wxd.message.notice('复制成功')">${row.logToken}</td>
            <td tips="true" style="width: 300px;">${row.desc}</td>
    </tr>
`;
        }

        $(() => {
            pageView = new PageView("/game/list", search, createRow);
            search();
        });

    </script>

</head>

<body>
<div class="btn_box" style="padding-left: 10px;padding-top: 8px; text-align: left;vertical-align: center;">
    <button type="button" onclick="wxd.loadHtml('/game-add.html','400px','240px',null,'-50px','-50px');">添加</button>
    <button type="button" onclick="search();">搜索</button>
    <br>
    <input id="search" type="text" value="" style="" onkeydown="if (event.keyCode===13)search();" placeholder="游戏ID或者游戏名字"/>
</div>
<div class="tableDom" style="position: absolute;left: 10px;top: 100px;right: 15px;bottom: 35px;">
    <table>
        <thead>
        <tr>
            <th style="width: 240px;">操作</th>
            <th style="width: 58px;">序号</th>
            <th style="width: 58px;">游戏ID</th>
            <th style="width: 120px;">名字</th>
            <th style="width: 120px;">ICON</th>
            <th style="width: 120px;">创建时间</th>
            <th style="width: 140px;">AppKey</th>
            <th style="width: 140px;">RechargeKey</th>
            <th style="width: 140px;">LogKey</th>
            <th style="width: 300px;">其它</th>
        </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>
</body>
</html>